package com.zero2oneblog.task;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zero2oneblog.entity.ApiAccessStatistics;
import com.zero2oneblog.service.IApiAccessStatisticsService;
import com.zero2oneblog.service.impl.ApiAccessStatisticsServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

@Component
public class ScheduledTask {

//    @Autowired
//    private IApiAccessStatisticsService iApiAccessStatisticsService;

    @Autowired
    private ApiAccessStatisticsServiceImpl apiAccessStatisticsService;

    @Scheduled(cron = "0 0 0/1 * * ?") // 每小时执行一次
//    @Scheduled(cron = "0 * * * * *") // 每分钟
//    @Scheduled(cron = "*/10 * * * * *")  // 每10秒
    public void updateApiAccessStatistics() {
        //那这里就要把所有的接口都得查出来然后去更新吗
        //先简化，只更新一个
        String apiName = "/public/apicountbytask";
        System.out.println("开始更新");
        apiAccessStatisticsService.updateBytask(apiName);

    }

//    @Scheduled(cron = "*/10 * * * * *")  // 每10秒
    @Scheduled(cron = "0 0 0/1 * * ?") // 每小时执行一次
    public void updateRedisApiAccessStatistics() {

        String apiName = "/public/apicountbyredis";
        System.out.println("开始更新/public/apicountbyredis");
        apiAccessStatisticsService.updateRedisBytask(apiName);

    }
}
